<template>
	<view>
		<view class="bg-video" style="height: 100vh;">
			<image src="../../static/img/indexbg.png" mode="aspectFill" class="w-all h-all"></image>
			<view class="w-all h-all" style="position: absolute;top: 0;left: 0;">
				<view class="text-center" style="padding: 230upx 120upx 0 120upx;">
					<image src="../../static/img/logo.png" mode="aspectFill" style="width: 260upx;height: 260upx;"
						class="round"></image>
					<view class="text999" style="margin-top: 180upx;">
						选择您的身份
					</view>
					<button class="cu-btn w-all round lg text-white margin-top-xl"
						style="height: 104upx;background-color: #008CFF;" @tap="login(0)">幼儿园</button>
					<button class="cu-btn w-all round lg text-white margin-top-xl"
						style="height: 104upx;background-color: #008CFF;" @tap="login(1)">小学</button>
					<view class="flex align-center" style="margin-top: 200upx;color: #333333;">
						<view class="flex-sub" @tap="login(2)">
							查询订单
						</view>
						<view class="" style="background-color: #333333;width: 2upx;height: 24upx;">

						</view>
						<view class="flex-sub" @tap="util.urlTo('about')">
							联系我们
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="cu-modal bottom-modal " :class="show ? 'show' : ''">
			<view class="cu-dialog  bg-no " @tap.stop="">
				<!-- <view class=" bg-white padding-left-sm padding-right-sm radius20" @getphonenumber="getPhoneNumber"
					open-type="getPhoneNumber">
					<view class="padding">
						绑定手机号
					</view>
				</view> -->
				<view class="padding-xl">
					<button class="cu-btn mybtn bg-white round text666" @getphonenumber="getPhoneNumber"
						open-type="getPhoneNumber">绑定手机号</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				mobile: ''
			}
		},
		onLoad() {},
		methods: {
			login(e) {
				let _this = this;
				let phone = uni.getStorageSync('user').mobile;
				if (phone) {
					uni.setStorageSync('mobileWx', phone);
					if (e == 2) {
						this.util.urlTo('order_list');
					} else {
						this.util.urlTo('order?school_type=' + e);
					}
					return false;
				}
				wx.login({
					success(res) {
						if (res.code) {
							console.log(res)
							_this.util.request('/login/wxLogin', {
								code: res.code
							}).then(res => {
								_this.openid = res.openid;
								uni.setStorageSync('openidWx', res.openid);
								uni.setStorageSync('user', res);
								_this.mobile = res.mobile;
								uni.setStorageSync('mobileWx', res.mobile);
								_this.identity(e);
							})
						} else {
							console.log('登录失败！' + res.errMsg)
						}
					}
				})
			},
			getPhoneNumber(e) {
				this.util.request('/login/wxGetPhone', {
					openid: this.openid,
					encryptedData: e.detail.encryptedData,
					iv: e.detail.iv,
					address: ''
				}).then(res => {
					this.mobile = res.mobile;
					this.show = false;
				})
			},
			identity(e) {
				this.util.urlTo('order?school_type=' + e);
				// if (this.mobile) {
				// 	this.util.urlTo('order?school_type=' + e);
				// } else {
				// 	this.show = true;
				// }
			}
		}
	}
</script>

<style>
	page {
		/* background-image: url('../../static/img/indexbg.png');
	width: 100%;
	height: 100vh;
	background-size: cover; */
	}
</style>